package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.Express;
import com.qj.yantaishan.service.IExpressService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 快递公司Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/Express")
public class ExpressController extends BaseController
{
    private String prefix = "yantaishan/Express";

    @Autowired
    private IExpressService expressService;

    @RequiresPermissions("yantaishan:express:view")
    @GetMapping()
    public String express()
    {
        return prefix + "/express";
    }

    /**
     * 查询快递公司列表
     */
    @RequiresPermissions("yantaishan:express:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Express express)
    {
        startPage();
        List<Express> list = expressService.selectExpressList(express);
        return getDataTable(list);
    }

    /**
     * 导出快递公司列表
     */
    @RequiresPermissions("yantaishan:express:export")
    @Log(title = "快递公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Express express)
    {
        List<Express> list = expressService.selectExpressList(express);
        ExcelUtil<Express> util = new ExcelUtil<Express>(Express.class);
        return util.exportExcel(list, "快递公司数据");
    }

    /**
     * 新增快递公司
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存快递公司
     */
    @RequiresPermissions("yantaishan:express:add")
    @Log(title = "快递公司", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Express express)
    {
        return toAjax(expressService.insertExpress(express));
    }

    /**
     * 修改快递公司
     */
    @RequiresPermissions("yantaishan:express:edit")
    @GetMapping("/edit/{pigcmsId}")
    public String edit(@PathVariable("pigcmsId") Long pigcmsId, ModelMap mmap)
    {
        Express express = expressService.selectExpressByPigcmsId(pigcmsId);
        mmap.put("express", express);
        return prefix + "/edit";
    }

    /**
     * 修改保存快递公司
     */
    @RequiresPermissions("yantaishan:express:edit")
    @Log(title = "快递公司", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Express express)
    {
        return toAjax(expressService.updateExpress(express));
    }

    /**
     * 删除快递公司
     */
    @RequiresPermissions("yantaishan:express:remove")
    @Log(title = "快递公司", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(expressService.deleteExpressByPigcmsIds(ids));
    }
}
